/**
 * @param {number[]} nums
 * @return {number}
*/
var maximumProduct = function(nums) {
  if(nums.length == 3) {
    return nums.reduce((pre, now) => {
      return pre * now;
    });
  }
  nums.sort((a, b) => a - b);
  return Math.max(nums[0] * nums[1] * nums[nums.length - 1], nums[nums.length - 1] * nums[nums.length - 2] * nums[nums.length - 3]);
};
let nums = [1,2,3];
console.log(maximumProduct(nums));
nums = [1,2,3,4];
console.log(maximumProduct(nums));
nums = [-1,-2,-3];
console.log(maximumProduct(nums));
